﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MovieRental_Presentation.Helpers;
using MovieRental.Entities;

namespace MovieRental_Presentation
{
	public partial class NewMovieDialog
	{
        private MovieInfo _movie;

		public NewMovieDialog()
		{
			this.InitializeComponent();
            _movie = new MovieInfo();
            _movie.ImdbRating = 5.0;
            DataContext = _movie;

			// Insert code required on object creation below this point.
		}

        private bool ValidateInput()
        {
            return (titleTextBox.Validate() &&
                imdbRatingTextBox.Validate() &&
                webPageTextBox.Validate());
        }

		private void backButton_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			this.NavigationService.GoBack();
		}

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            if (!ValidateInput())
                return;
            ComponentManager.Instance.MovieComponent.AddOrUpdate(_movie);
            this.NavigationService.GoBack();
        }
	}
}